package com.hanhai.zrb.backend.web.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSONObject;
import com.hanhai.common.web.controller.BaseController;
import com.hanhai.zrb.api.biz.service.ResourceMatchService;
import com.hanhai.zrb.api.biz.service.impl.ResourceMatchServiceSolrImpl;
import com.hanhai.zrb.model.resourcematch.ResourceMatchLevelEnum;
import com.hanhai.zrb.model.resourcematch.ResourceMatchResult;
import com.hanhai.zrb.model.resourcematch.ResourceMatchTypeEnum;

@Controller
@RequestMapping("resourcematchtest")
public class ResourceMatchTestController extends BaseController{

	@Resource
	private ResourceMatchServiceSolrImpl resourceMatchServiceSolr;
		
	@Resource
	private ResourceMatchService resourceMatchService;
	
	//测试用的
	@RequestMapping("match")
	public void match(@RequestParam Integer type,@RequestParam Long bizid, HttpServletResponse response){
		if(!ResourceMatchTypeEnum.exist(type)){
			 super.jsonFail(response, "The type is illegal~");
			 return;
		}
		ResourceMatchResult list=resourceMatchServiceSolr.match(type, bizid);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", list);
		super.returnJsonObject(response, jsonObject );	
	}
	
	@RequestMapping("recommend")
	public void recommend(@RequestParam Integer type,@RequestParam Long bizid, HttpServletResponse response){
		ResourceMatchResult list=resourceMatchService.recommend(type, bizid);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", list);
		super.returnJsonObject(response, jsonObject );	
	}
	
	@RequestMapping("matchpage")
	public void matchPage(@RequestParam Integer type,@RequestParam Long bizid, @RequestParam Integer level,Integer pageNo,Integer pageSize,HttpServletResponse response){
		ResourceMatchLevelEnum enumLevel=ResourceMatchLevelEnum.enumLevel(level);
		if(enumLevel == null){
			super.jsonFail(response, "Level is illegal,level="+level);
		}
		ResourceMatchResult page=resourceMatchService.matchPage(type, bizid, pageNo, pageSize,enumLevel);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("page", page);
		super.returnJsonObject(response, jsonObject );	
	}
}
